package com.amigo.online.provider.adv.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.provider.adv.entity.AdvHomeLookRecord;
import com.amigo.online.provider.adv.mapper.AdvHomeLookRecordMapper;
import com.amigo.online.provider.adv.service.AdvHomeLookRecordService;
import com.amigo.online.provider.adv.service.AdvHomeStockService;

@Service
public class AdvHomeLookRecordServiceImpl implements AdvHomeLookRecordService {

    @Autowired
    AdvHomeLookRecordMapper advHomeLookRecordMapper;

    @Autowired
    AdvHomeStockService advHomeStockService;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void recordHomeAdvLooked(Long advId, String device, Long userId) {
        AdvHomeLookRecord record = new AdvHomeLookRecord(advId, userId, device);
        //记录数据
        advHomeLookRecordMapper.insert(record);
    }

    @Override
    public void recordHomeAdvLooked(long advId, String sex, Long age, Double lng, Double lat, String city) {
        AdvHomeLookRecord record = new AdvHomeLookRecord(advId, sex, age, lng, lat, city);
        advHomeLookRecordMapper.insert(record);
        advHomeStockService.deductionHomeAdvLookStock(advId);
    }

}
